﻿using Bank.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Bank
{
    public class Banker
    {

        private String  firstName;
        public String FirstName
        {
            get { return firstName; }
            set { firstName = value; }
        }

        private String lastname;
        public String LastName
        {
            get { return lastname; }
            set { lastname = value; }
        }

        private ClientCollections clients;
        
        public ClientCollections Clients { 
            get { return clients; } 
        }

        public Banker(String fName, String lName)
        {
            this.firstName = fName;
            this.lastname = lName;
            clients = new ClientCollections();
        }

        public void addClient(String firstName, String lastName, String pesel)
        {            
            Client tmp = clients.getClient(pesel);
            if (tmp == null)
                clients.addClient(firstName, lastname, pesel);
            else
                throw new ClientExsistException("Client " + pesel + " exsist in database");
        }

        public Client getClient(Int32 clientID)
        {
            return clients.getClient(clientID);
        }

        public Client getClient(String pesel)
        {
            return clients.getClient(pesel);
        }

        public void requestNewAccount(AccountType type, Int32 clientID, decimal ballance)
        {
            Client client = getClient(clientID);
            client.requestNewAccount(type, client.ClientID, ballance);          
        }

        public void requestNewAccount(AccountType type, Int32 clientID, Money ballance)
        {
            Client client = getClient(clientID);
            client.requestNewAccount(type, client.ClientID, ballance);
        }

        public void removeClient(Int32 clientID)
        {
            clients.removeClient(clientID);
        }

        public void blockClient(Int32 clientID)
        {
            Client client = clients.getClient(clientID);
            client.Blocked = true;
        }
        public void unBlockClient(Int32 clientID)
        {
            Client client = clients.getClient(clientID);
            client.Blocked = false;
        }

        public void listAllClients()
        {
            clients.listClients();
        }
        
        public void calculateInterests(Int32 clientID, String accountID)
        {
            Client client = clients.getClient(clientID);

            List<IAccount> accountList = client.Manager.getAllAccounts(client.Accounts , client.ClientID);

            foreach (IAccount account in accountList)
            {
                account.CalculateMyInterest();    
               
            }          
            
        }
    }
}
